//
//  KABCosPublishCCell.m
//  kabu
//
//  Created by XiangDongMBP on 2017/2/8.
//  Copyright © 2017年 East. All rights reserved.
//

#import "KABCosPublishCCell.h"
#import "KABModel.h"
#import "UIColor+XDHex.h"
#import <YYWebImage.h>
#import "NSString+XDQiniu.h"

@interface KABCosPublishCCell ()
@property (nonatomic, strong) UIImage *addImg;
@end

@implementation KABCosPublishCCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.addImg = [UIImage imageNamed:@"cos_pub_add"];
    self.BgImgView.layer.borderColor = [UIColor xd_colorWithHex:0xCCCCCC].CGColor;
    [self.closeBtn addTarget:self action:@selector(closeBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)closeBtnTapped:(UIButton *)btn {
    if ([self.delegate respondsToSelector:@selector(KABCosPublishCCell:deleteBtnTapped:)]) {
        [self.delegate KABCosPublishCCell:self deleteBtnTapped:btn];
    }
}

- (void)setIsAdd:(BOOL)isAdd {
    _isAdd = isAdd;
    if (isAdd) {
        self.BgImgView.image = self.addImg;
    }
}

- (void)configViewWithPublishItem:(KABCosPublishItem *)item {
    if (item) {
        self.BgImgView.image = item.img;
        self.BgImgView.contentMode = UIViewContentModeScaleAspectFill;
        self.BgImgView.layer.borderWidth = 0;
        self.closeBtn.hidden = NO;
    } else {
        self.BgImgView.image = self.addImg;
        self.BgImgView.contentMode = UIViewContentModeCenter;
        self.BgImgView.layer.borderWidth = 1;
        self.closeBtn.hidden = YES;
    }
}

@end


@implementation KABCosPublishCCell (ThemePreview)
- (void)configViewWithSkinDetImgItem:(KABSkinDetImgItem *)item {
    self.closeBtn.hidden = YES;
    self.BgImgView.contentMode = UIViewContentModeScaleAspectFill;
    self.BgImgView.layer.borderWidth = 0;
    [self.BgImgView yy_setImageWithURL:[NSURL URLWithString:item.introduce_img_url]
                                 placeholder:[KABDefaultVarModel sharedInstance].rectDefaultImg];
}

@end


@implementation KABCosPublishCCell (HomepageAlbum)
- (void)configViewWithPhotoItem:(KABMinePhotoItem *)item {
    self.closeBtn.hidden = YES;
    self.BgImgView.contentMode = UIViewContentModeScaleAspectFill;
    self.BgImgView.layer.borderWidth = 0;
    
    NSString *thumbImgUrl = [item.image_url xd_qiniuImgUrlWithMaxWidth:CGRectGetWidth(self.BgImgView.frame)];
    [self.BgImgView yy_setImageWithURL:[NSURL URLWithString:thumbImgUrl]
                           placeholder:[KABDefaultVarModel sharedInstance].smallDefaultImg];
}
@end
